// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   register_draft_ok.java

package oa.planing;

import com.jspsmart.upload.*;
import include.nseer_cookie.*;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import java.util.StringTokenizer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;

public class register_draft_ok extends HttpServlet
{

	public register_draft_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		ServletContext dbApplication = dbSession.getServletContext();
		try
		{
			HttpSession session = request.getSession();
			ServletContext context = session.getServletContext();
			String path = context.getRealPath("/");
			counter count = new counter(dbApplication);
			SmartUpload mySmartUpload = new SmartUpload();
			mySmartUpload.setCharset("UTF-8");
			nseer_db_backup1 oa_db = new nseer_db_backup1(dbApplication);
			if (oa_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				mySmartUpload.initialize(pageContext);
				String file_type = getFileLength.getFileType((String)session.getAttribute("unit_db_name"));
				long d = getFileLength.getFileLength((String)session.getAttribute("unit_db_name"));
				mySmartUpload.setMaxFileSize(d);
				mySmartUpload.setAllowedFilesList(file_type);
				String meeting_subject = request.getParameter("meeting_subject");
				try
				{
					mySmartUpload.upload();
					String file_name[] = new String[mySmartUpload.getFiles().getCount()];
					String begin_time = mySmartUpload.getRequest().getParameter("begin_time");
					int filenum1 = count.read((String)dbSession.getAttribute("unit_db_name"), "oaPlaningcount");
					String planing_ID = (new StringBuilder(String.valueOf(begin_time))).append("-").append(filenum1).toString();
					count.write((String)dbSession.getAttribute("unit_db_name"), "oaPlaningcount", filenum1);
					String sql1 = (new StringBuilder("select * from oa_planing where planing_ID='")).append(planing_ID).append("'").toString();
					ResultSet rs = oa_db.executeQuery(sql1);
					if (rs.next())
					{
						response.sendRedirect("oa/planing/register_ok_a.jsp");
					} else
					{
						for (int i = 0; i < mySmartUpload.getFiles().getCount(); i++)
						{
							SmartFile file = mySmartUpload.getFiles().getFile(i);
							if (file.isMissing())
							{
								file_name[i] = "";
							} else
							{
								int filenum = count.read((String)dbSession.getAttribute("unit_db_name"), "oaAttachmentcount");
								count.write((String)dbSession.getAttribute("unit_db_name"), "oaAttachmentcount", filenum);
								file_name[i] = (new StringBuilder(String.valueOf(filenum))).append(file.getFileName()).toString();
								file.saveAs((new StringBuilder(String.valueOf(path))).append("oa/file_attachments/").append(filenum).append(file.getFileName()).toString());
							}
						}

						String subject = mySmartUpload.getRequest().getParameter("subject");
						String id = mySmartUpload.getRequest().getParameter("id");
						String planing_type = mySmartUpload.getRequest().getParameter("planing_type");
						String human_name = "";
						String human_ID = "";
						String end_time = mySmartUpload.getRequest().getParameter("end_time");
						String select4 = mySmartUpload.getRequest().getParameter("select4");
						String register = mySmartUpload.getRequest().getParameter("register");
						String register_ID = mySmartUpload.getRequest().getParameter("register_ID");
						String register_time = mySmartUpload.getRequest().getParameter("register_time");
						String human = mySmartUpload.getRequest().getParameter("human");
						String content = mySmartUpload.getRequest().getParameter("content");
						String fileKind_chain = mySmartUpload.getRequest().getParameter("fileKind_chain");
						String chain_id = Divide1.getId(fileKind_chain);
						String chain_name = Divide1.getName(fileKind_chain);
						if (human != null && !human.equals(""))
						{
							for (StringTokenizer tokenTO1 = new StringTokenizer(human, "/"); tokenTO1.hasMoreTokens();)
							{
								human_ID = tokenTO1.nextToken();
								human_name = tokenTO1.nextToken();
							}

							String sql2 = (new StringBuilder("select * from hr_file where human_ID='")).append(human_ID).append("'").toString();
							ResultSet rs2 = oa_db.executeQuery(sql2);
							if (rs2.next())
							{
								chain_id = rs2.getString("chain_id");
								chain_name = rs2.getString("chain_name");
							}
						}
						String sqla = "insert into oa_planing(register,register_ID,register_time,planing_ID,subject,meeting_subject,type,begin_time,end_time,content,chain_id,chain_name,human_ID,human_name,check_tag";
						String sqlb = (new StringBuilder(") values ('")).append(register).append("','").append(register_ID).append("','").append(register_time).append("','").append(planing_ID).append("','").append(subject).append("','").append(meeting_subject).append("','").append(planing_type).append("','").append(begin_time).append("','").append(end_time).append("','").append(content).append("','").append(chain_id).append("','").append(chain_name).append("','").append(human_ID).append("','").append(human_name).append("','5'").toString();
						for (int i = 0; i < mySmartUpload.getFiles().getCount(); i++)
						{
							int p = i + 1;
							sqla = (new StringBuilder(String.valueOf(sqla))).append(",attachment").append(p).toString();
							sqlb = (new StringBuilder(String.valueOf(sqlb))).append(",'").append(file_name[i]).append("'").toString();
						}

						String sql = (new StringBuilder(String.valueOf(sqla))).append(sqlb).append(")").toString();
						oa_db.executeUpdate(sql);
						String sql2 = (new StringBuilder("delete from oa_planing where id='")).append(id).append("'").toString();
						oa_db.executeUpdate(sql2);
						response.sendRedirect("oa/planing/register_draft_ok.jsp?finished_tag=0");
					}
				}
				catch (Exception ex)
				{
					response.sendRedirect((new StringBuilder("oa/planing/register_ok_c.jsp?meeting_subject=")).append(meeting_subject).toString());
				}
				oa_db.commit();
				oa_db.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
